package persistent.prestige.module.ums.model;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import persistent.prestige.platform.base.model.AuditableModel;
import persistent.prestige.platform.base.utils.StringUtils;
import persistent.prestige.platform.security.model.Role;
import persistent.prestige.platform.security.model.User;

/**
 * @Title:User.java
 * @Package persistent.prestige.ums.model
 * @Description 系统用户表
 * @author prestigeding
 * @date 2012-12-12 下午11:16:43
 * @version V1.0
 */
public class UmsUser extends AuditableModel implements User {

	/** 普通属性 */
	/** 登录名 */
	private String userName;

	/** 真实姓名 */
	/** 登录名 */
	private String trueName;

	/** 密码 */
	private String password;

	/** 确认密码 */
	private String confmPwd;

	/** 电话 */
	private String tel;

	/** 手机 */
	private String mobile;

	/** 邮政编码 */
	private String postcode;

	/** email */
	private String email;

	/** 地址 */
	private String address;

	/**
	 * 是否有效 1:启用 0:禁用
	 */
	private String status;
	
	/** email验证标识 */
	private String emailVerify;


	/** 对象属性 */

	/** 所属角色 */
	private Set<UmsRole> roles = new HashSet<UmsRole>(1);

	/** 用户所属机构 */
	private UmsOrganization organization;


	/** 非数据库字段 */
	private String roleIds;
	private String roleNames;

	public UmsUser(){
	}

	/** gets and sets */
	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}
	
	public String getPassword() {
		return password;
	}

	public String getTrueName() {
		return trueName;
	}

	public void setTrueName(String trueName) {
		this.trueName = trueName;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	
	public String getConfmPwd() {
		return StringUtils.isNotEmpty(this.confmPwd) ? confmPwd : password;
	}

	public void setConfmPwd(String confmPwd) {
		this.confmPwd = confmPwd;
	}

	public String getTel() {
		return tel;
	}

	public void setTel(String tel) {
		this.tel = tel;
	}

	public String getMobile() {
		return mobile;
	}

	public void setMobile(String mobile) {
		this.mobile = mobile;
	}

	public String getPostcode() {
		return postcode;
	}

	public void setPostcode(String postcode) {
		this.postcode = postcode;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getAddress() {
		return address;
	}

	public void setAddress(String address) {
		this.address = address;
	}


	public String getStatus() {
		return status;
	}

	public void setStatus(String status) {
		this.status = status;
	}

	
	public String getEmailVerify() {
		return emailVerify;
	}

	public void setEmailVerify(String emailVerify) {
		this.emailVerify = emailVerify;
	}

	public Set<UmsRole> getRoles() {
		return roles;
	}

	public void setRoles(Set<UmsRole> roles) {
		this.roles = roles;
	}

	public UmsOrganization getOrganization() {
		return organization;
	}

	public void setOrganization(UmsOrganization organization) {
		this.organization = organization;
	}

	public List<Integer> getRoleIds() {
		if(this.roles == null || this.roles.isEmpty() ) return null;
		List<Integer> list = new ArrayList<Integer>();
		for (Iterator<UmsRole> it = this.roles.iterator(); it.hasNext();) {
			UmsRole r =  it.next();
			list.add(r.getId());
		}
		return list;
	}

	public String getRoleNames() {
		if(this.roles == null || this.roles.isEmpty()) return "";
		String roleNames = "";
		for (Iterator<UmsRole> it = this.roles.iterator(); it.hasNext();) {
			UmsRole r =  it.next();
			roleNames += "," + r.getRoleName() ;
		}
		return StringUtils.substring(roleNames, 1);
	}

	public String getLoginName() {
		return getUserName();
	}

	public Set<? extends Role> getAllRoles() {
		return (Set<? extends Role>) getRoles();
	}


}
